#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n, a[N];

int dfs(int l, int r)
{
	if(l >= r) return a[l];
	int mid = l + r >> 1;
	int left = dfs(l, mid);
	int right = dfs(mid + 1, r);
	int t1 = mid, sum1 = 0, ret1 = -INF;
	while(t1 >= l)
	{	
		sum1 += a[t1 --];
		ret1 = max(ret1, sum1);
	}
	int t2 = mid + 1, sum2 = 0, ret2 = -INF;
	while(t2 <= r)
	{
		sum2 += a[t2 ++];
		ret2 = max(ret2, sum2);
	}
	return max(left, max(right, ret1 + ret2));
}

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	cout << dfs(1, n) << endl;
	return 0;
}